<template>
  <div
    class="singleDiv"
    ref="singleDiv"
  >
    <!-- input内容框 -->
    <div class="singleName">
      <el-input
        v-model="data.name"
        :disabled="isDisabled"
        clearable
      /><i
        class="el-icon-edit editBtn"
        @click="editName()"
      ></i>
    </div>
    <!-- 每一个图片 -->
    <div :class="['infoWarp',isShow==true?'infoBG':'']">
      <img
        :src="src"
        alt=""
        class="singlePic"
        @mouseenter="showInfo(event)"
        @mouseleave="isShow = false"
      />
    </div>
    <!-- 鼠标放上去显示的内容 -->
    <div
      class="infoWin"
      ref="infoWin"
      v-show="isShow"
    >
      <p>{{ data.Internet }}</p>
      <p>{{ data.intranet }}</p>
    </div>
  </div>
</template>

<script>
export default {
  // import引入的组件需要注入到对象中才能使用
  components: {},
  props: {
    data: {
      required: true,
      type: Object,
    },
  },
  data() {
    // 这里存放数据
    return {
      // name: "负载均衡服务器LBS-1",
      // id: "testID",
      // Internet: "39.99.165.58",
      // intranet: "172.26.137.195",
      // status:'normal',
      isDisabled: true,
      isShow: false,
    };
  },
  // 监听属性 类似于data概念
  computed: {
    left: function () {
      return this.data.x + "px";
    },
    top: function () {
      return this.data.y + "px";
    },
    src: function () {
      let obj = {
        normal: "/static/image/board/board_normal.png",
        error: "/static/image/board/board_error.png",
        warning: "/static/image/board/board_warn.png",
        offline: "",
      };
      return obj[this.data.status];
    },
  },
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.setUI();
  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeDestroy() {}, // 生命周期 - 销毁之前
  // 方法集合
  methods: {
    editName() {
      // 点击修改名称，
      this.isDisabled = !this.isDisabled;
      console.log(123);
    },
    showInfo(e) {
      // hover弹窗详情
      // console.log("e: ", e);
      // this.$refs['infoWin'].style.left=e.target.left;
      this.isShow = true;
    },
    setUI() {
      this.$refs["singleDiv"].style.setProperty("--left", this.left);
      this.$refs["singleDiv"].style.setProperty("--top", this.top);
    },
  },
};
</script>


<style lang='less' scoped>
//@import url(); 引入公共css类
// 最外层样式
.singleDiv {
  position: absolute;
  left: var(--left);
  top: var(--top);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-content: center;
  font-size: 14px;
  font-weight: 400;
  z-index: 2;
}
// input内容框样式
.singleName {
  width: 160px;
  height: 40px;
  line-height: 40px;
  border-radius: 4px;
  background: #00589a;
  display: flex;
  justify-content: space-between;
  align-items: center;
  ::v-deep .el-input {
    margin: 0;
    width: 90%;
  }
  ::v-deep .el-input__inner {
    width: 100%;
    background-color: #00589a;
    border: none;
    padding: 0 4px;
    color: #ffffff;
  }
}
// 笔
.editBtn {
  cursor: pointer;
  width: 24px;
  height: 24px;
  line-height: 24px;
  margin: 0 3px;
  border-radius: 4px;
  color: #9fdbff;
  border: 1px solid #9fdbff;
}
// 图片样式
.infoWarp {
  width: 90px;
  height: 80px;
  border-radius: 8px;
  margin: 8px auto;
}
// 图片样式
.infoBG {
  background: rgba(0, 220, 255, 0.2);
  opacity: Alpha(opacity=20);
}
// 图片样式
.singlePic {
  margin: 0 auto;
  cursor: pointer;
}
// 鼠标放上去
.infoWin {
  position: absolute;
  width: 200px;
  height: 80px;
  left: 100px;
  background: #1d3561;
  border: 1px solid #4b8ad7;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-content: center;
}
</style>